# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

CONFIGURE_SUBST_FILES += ['cairo-features.h']

EXPORTS.cairo += [
    '!cairo-features.h',
    'cairo-deprecated.h',
    'cairo-platform.h',
    'cairo-rename.h',
    'cairo-tee.h',
    'cairo-version.h',
    'cairo.h',
    'pixman-rename.h',
]

if CONFIG['MOZ_WIDGET_TOOLKIT'] not in ('uikit'):
    EXPORTS.cairo += [
        'cairo-pdf.h',
    ]
    SOURCES += [
        'cairo-base85-stream.c',
        'cairo-cff-subset.c',
        'cairo-deflate-stream.c',
        'cairo-pdf-operators.c',
        'cairo-pdf-surface.c',
        'cairo-truetype-subset.c',
        # cairo-type1-subset.c should be here, but it's only supported on freetype platforms
        'cairo-type1-fallback.c',
        'cairo-type3-glyph-surface.c',
    ]

if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
    EXPORTS.cairo += [
        'cairo-win32.h',
    ]
    if CONFIG['MOZ_ENABLE_DWRITE_FONT']:
        SOURCES += [
            'cairo-dwrite-font.cpp',
        ]
    if CONFIG['MOZ_ENABLE_D2D_SURFACE']:
        SOURCES += [
            'cairo-d2d-surface.cpp',
        ]
    SOURCES += [
        'cairo-win32-font.c',
        'cairo-win32-surface.c',
    ]
    DEFINES['DISABLE_SOME_FLOATING_POINT'] = True
    DEFINES['CAIRO_WIN32_STATIC_BUILD'] = True
    if CONFIG['NS_PRINTING']:
        SOURCES += [
            'cairo-win32-printing-surface.c',
        ]
    else:
        DEFINES['CAIRO_OMIT_WIN32_PRINTING'] = True
elif CONFIG['MOZ_WIDGET_TOOLKIT'] in {'uikit'}:
    EXPORTS.cairo += [
        'cairo-quartz-image.h',
        'cairo-quartz.h',
    ]
    SOURCES += [
        'cairo-quartz-font.c',
        'cairo-quartz-image-surface.c',
        'cairo-quartz-surface.c',
    ]
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'beos':
    EXPORTS.cairo += [
        'cairo-beos.h',
    ]
    SOURCES += [
        'cairo-beos-surface.cpp',
    ]
elif 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
    EXPORTS.cairo += [
        'cairo-ps.h',
    ]
    SOURCES += [
        'cairo-ps-surface.c',
    ]

if CONFIG['MOZ_X11']:
    EXPORTS.cairo += [
        'cairo-xlib-xrender.h',
        'cairo-xlib.h',
    ]
    SOURCES += [
        'cairo-xlib-display.c',
        'cairo-xlib-screen.c',
        'cairo-xlib-surface.c',
        'cairo-xlib-visual.c',
    ]

if CONFIG['MOZ_ENABLE_CAIRO_FT']:
    EXPORTS.cairo += [
        'cairo-ft.h',
    ]
    SOURCES += [
        'cairo-ft-font.c',
        'cairo-type1-subset.c',
    ]

SOURCES += [
    'cairo-bentley-ottmann-rectangular.c', # redefinition of '_cairo_bo_trap'
    'cairo-bentley-ottmann-rectilinear.c', # redefinition of '_cairo_bo_trap'
    'cairo-bentley-ottmann.c', # redefinition of '_cairo_bo_trap'
    'cairo-surface-wrapper.c', #  redefinition of '_copy_transformed_pattern'
]

SOURCES += [
    'cairo-analysis-surface.c',
    'cairo-arc.c',
    'cairo-array.c',
    'cairo-atomic.c',
    'cairo-base64-stream.c',
    'cairo-botor-scan-converter.c',
    'cairo-boxes.c',
    'cairo-cache.c',
    'cairo-clip.c',
    'cairo-color.c',
    'cairo-composite-rectangles.c',
    'cairo-debug.c',
    'cairo-device.c',
    'cairo-fixed.c',
    'cairo-font-face-twin-data.c',
    'cairo-font-face-twin.c',
    'cairo-font-face.c',
    'cairo-font-options.c',
    'cairo-freed-pool.c',
    'cairo-freelist.c',
    'cairo-gstate.c',
    'cairo-hash.c',
    'cairo-hull.c',
    'cairo-image-info.c',
    'cairo-image-surface.c',
    'cairo-lzw.c',
    'cairo-matrix.c',
    'cairo-misc.c',
    'cairo-mutex.c',
    'cairo-observer.c',
    'cairo-output-stream.c',
    'cairo-paginated-surface.c',
    'cairo-path-bounds.c',
    'cairo-path-fill.c',
    'cairo-path-fixed.c',
    'cairo-path-in-fill.c',
    'cairo-path-stroke.c',
    'cairo-path.c',
    'cairo-pattern.c',
    'cairo-pen.c',
    'cairo-polygon.c',
    'cairo-recording-surface.c',
    'cairo-rectangle.c',
    'cairo-rectangular-scan-converter.c',
    'cairo-region.c',
    'cairo-scaled-font-subsets.c',
    'cairo-scaled-font.c',
    'cairo-slope.c',
    'cairo-spans.c',
    'cairo-spline.c',
    'cairo-stroke-style.c',
    'cairo-surface-clipper.c',
    'cairo-surface-fallback.c',
    'cairo-surface-offset.c',
    'cairo-surface-snapshot.c',
    'cairo-surface-subsurface.c',
    'cairo-surface.c',
    'cairo-tee-surface.c',
    'cairo-tor-scan-converter.c',
    'cairo-toy-font-face.c',
    'cairo-traps.c',
    'cairo-unicode.c',
    'cairo-user-font.c',
    'cairo-version.c',
    'cairo-wideint.c',
    'cairo.c',
]

# We allow warnings for third-party code that can be updated from upstream.
ALLOW_COMPILER_WARNINGS = True

FINAL_LIBRARY = 'gkmedias'

DEFINES['PACKAGE_VERSION'] = '"moz"'
DEFINES['PACKAGE_BUGREPORT'] = '"http://bugzilla.mozilla.org/"'

for var in ('CAIRO_HAS_PTHREAD', '_GNU_SOURCE'):
    DEFINES[var] = True

for var in ('MOZ_TREE_CAIRO', 'MOZ_TREE_PIXMAN'):
    if CONFIG[var]:
        DEFINES[var] = True

if CONFIG['GNU_CC']:
    DEFINES['HAVE_CXX11_ATOMIC_PRIMITIVES'] = True
    # We would normally use autoconf to set these up, using AC_CHECK_SIZEOF.
    # But AC_CHECK_SIZEOF requires running programs to determine the sizes,
    # and that doesn't work so well with cross-compiling.  So instead we
    # use these magic macros, available since at least GCC 4.3, to define
    # the preprocessor macros cairo wanted from autoconf.
    DEFINES['SIZEOF_VOID_P'] = '__SIZEOF_POINTER__'
    DEFINES['SIZEOF_INT'] = '__SIZEOF_INT__'
    DEFINES['SIZEOF_LONG'] = '__SIZEOF_LONG__'
    DEFINES['SIZEOF_LONG_LONG'] = '__SIZEOF_LONG_LONG__'

# Normally determined by cairo's configure script.
DEFINES['HAVE_UINT64_T'] = True

if CONFIG['MOZ_TREE_FREETYPE']:
    DEFINES['HAVE_FT_LIBRARY_SETLCDFILTER'] = True
    DEFINES['FT_LCD_FILTER_H'] = '%s/modules/freetype2/include/freetype/ftlcdfil.h' % TOPSRCDIR

# Suppress warnings in third-party code.
if CONFIG['_MSC_VER']:
    CFLAGS += [
        '-wd4005',
        '-wd4146',
    ]
if CONFIG['GNU_CC'] or CONFIG['CLANG_CL']:
    CFLAGS += [
        '-Wno-enum-compare',
        '-Wno-int-to-pointer-cast',
        '-Wno-sign-compare',
        '-Wno-type-limits',
        '-Wno-missing-field-initializers',
        '-Wno-conversion',
        '-Wno-unused-but-set-variable',
    ]
if CONFIG['CLANG_CXX'] or CONFIG['CLANG_CL']:
    CFLAGS += [
        '-Wno-incompatible-pointer-types',
        '-Wno-tautological-compare',
        '-Wno-tautological-constant-out-of-range-compare',
        '-Wno-error=uninitialized',
    ]
if CONFIG['CLANG_CL']:
    CFLAGS += [
        '-Wno-deprecated-register',
        '-Wno-macro-redefined',
        '-Wno-unused-variable',
    ]

if CONFIG['MOZ_X11']:
    CFLAGS += CONFIG['XCFLAGS']

if CONFIG['MOZ_ENABLE_CAIRO_FT']:
    CFLAGS += CONFIG['CAIRO_FT_CFLAGS']
    CXXFLAGS += CONFIG['CAIRO_FT_CFLAGS']
